/* =============================================================
 * System Name：Document Control System
 * File Name： WeiboApi.java
 * --------------------------------------------------------------
 * (C) Copyright M+W Group 2012 All Rights Reserved.
 *
 *  VERSION    DATE        BY                CHANGE/COMMENT
 * ----------------------------------------------------------------
 *
 */
package com.deco.authorization.api;

import java.net.URLEncoder;

import org.scribe.builder.api.DefaultApi10a;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.Token;

public class WeiboApi extends DefaultApi10a {

	private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s&oauth_callback=%s";
	private static final String REQUEST_TOKEN_RESOURCE = "api.t.sina.com.cn/oauth/request_token";
	private static final String ACCESS_TOKEN_RESOURCE = "api.t.sina.com.cn/oauth/access_token";
	// due to the restriction of sina oauth api, we have to put the callback url
	// here.
	private String CALLBACK_URL;

	@Override
	public String getAccessTokenEndpoint() {
		return "http://" + ACCESS_TOKEN_RESOURCE;
	}

	@Override
	public String getRequestTokenEndpoint() {
		return "http://" + REQUEST_TOKEN_RESOURCE;
	}

	@Override
	public String getAuthorizationUrl(Token requestToken) {
		return String.format(AUTHORIZE_URL, requestToken.getToken(), URLEncoder
				.encode(CALLBACK_URL));
	}

	public void setCallbackURL(String callbackURL) {
		CALLBACK_URL = callbackURL;
	}

}
